<%@ Page Language="C#" MasterPageFile="~/FiledbookMaster.Master" AutoEventWireup="true" CodeBehind="AddStorageTransaction.aspx.cs" Inherits="Fieldbook.Testwebsite.User.AddStorageTransaction" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script type="text/javascript">
        function roundNumber(rnum) 
        {
	        var rlength = 2; // The number of decimal places to round to
	        var newnumber = String(Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength));
			var dot = newnumber.indexOf('.');
			if(dot == -1){
				newnumber += '.'; 
				dot = newnumber.indexOf('.');
			}
			while(newnumber.length <= dot + rlength) { newnumber += '0'; }			
	        return newnumber;
		}        
		
        function CalculateTotal()
        {
            var pricePerUnit = document.getElementById('<%= this.txtPricePerUnit.ClientID %>').value;
            var units = document.getElementById('<%= this.txtQuota.ClientID %>').value;
            if (pricePerUnit != null && units != null)
            {
                var total = roundNumber(pricePerUnit * units);
                document.getElementById('<%= this.txtTotal.ClientID %>').value = total;   
            }
        }
    </script>
    <asp:Label ID="lblOperationStatus" runat="server" EnableViewState="false"/>
    <asp:Panel ID="AddResourceTransaction" runat="server">
    <table>
        <tr>
            <td>Category: </td>
            <td>
                <asp:DropDownList id="ddlResourceCategory1" runat="server" 
                    DataSourceID="ResouceCategoriesODS"
                    DataValueField="CategoryID"
                    DataTextField="Description" 
                    AutoPostBack="true"
                    OnSelectedIndexChanged="ddlResourceCategory1_SelectedIndexChanged"
                    OnDataBound="ddlResourceCategory1_SelectedIndexChanged"/>
            </td>
        </tr>
        <tr>
            <td>Resource: </td>
            <td>
                <asp:DropDownList ID="ddlResourceItem" runat="server"
                    DataValueField="ResourceID"
                    DataTextField="Description"/>
            </td>
        </tr>
        <tr>
            <td>Transaction type: </td>
            <td>
                <asp:DropDownList ID="ddlTranactionType" runat="server"/>
            </td>
        </tr>
        <tr>
            <td>Price per unit: </td>
            <td>
                <asp:TextBox ID="txtPricePerUnit" runat="server" CssClass="txtnumber"/>
            </td>
        </tr>
        <tr>
            <td>Quota: </td>
            <td>
                <asp:TextBox ID="txtQuota" runat="server" CssClass="txtnumber"/>
            </td>
        </tr>
        <tr>
            <td>Total:</td>
            <td>
                <asp:TextBox ID="txtTotal" runat="server" onFocus="CalculateTotal()" CssClass="txtnumber"/>
            </td>
        </tr>
        <tr>
        <td colspan="2">
            <asp:LinkButton Id="linkAddResourceTransacton" Text="Add" runat="server" onCommand="linkAddResourceTransacton_Command"/>
        </td>
        </tr>
    </table>
    <br />
    </asp:Panel>
    <br />
    
    <asp:ObjectDataSource ID="ResouceCategoriesODS" runat="server" TypeName="Fieldbook.Business.ResourceController" SelectMethod="LoadResourceCategories">
        <SelectParameters>
            <asp:SessionParameter Name="userID" Type="Int64" SessionField="userID" />
        </SelectParameters>
    </asp:ObjectDataSource>
</asp:Content>
